/**
 * 创建人：王曙光
 * 创建时间：2011-9-10
 * 功能描述：网络数据访问
 */
var Net = function() {
	return {
		//检测网络环境是否可用
		CheckNet : function(url, err, succeed) {
			var monitor = new air.URLMonitor(new air.URLRequest(url));
			monitor.addEventListener(air.StatusEvent.STATUS, function(e) {
				if(!monitor.available) {
					err();
				} else {
					succeed();
				}
			});
			monitor.start();
		},
		//以POST方式请求网络数据
		getJSON : function(url, variables, succeed, error) {
			var params = url.split("/");
			var turl = "";
			for(var i = 0; i < params.length - 1; i++) {
				if(i == params.length - 2)
					turl += params[i];
				else
					turl += params[i] + "/";
			}
			Net.CheckNet(turl, function() {
				error("网络连接失败");
			}, function() {				
				var request = new air.URLRequest();
				request.url = url;				
				request.method = air.URLRequestMethod.POST;
				request.data = variables;
				//设置参数数据的编码格式为utf-8防止中文乱码
				request.contentType = "application/x-www-form-urlencoded; charset=utf-8";
				var loader = new air.URLLoader();
				loader.dataFormat = air.URLLoaderDataFormat.TEXT;
				loader.addEventListener(air.Event.COMPLETE, function(event) {
					var $json = $(event.target.data);
					succeed(JSON.parse($json.text()));
				});
				try {
					loader.load(request);
				} catch (msg) {
					error(msg);
				}
			});
		}
	}
}();
